﻿// JScript 文件
//**********************
//功能---全选复选框
//使用---AdminUser
//**********************
function SelectAllCheckboxes(spanChk,selectid){
　var oItem = spanChk.children;
　var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
　xState=theBox.checked;
　elm=theBox.form.elements;
　for(i=0;i<elm.length;i++)
　    if (selectid != null){
　        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id && elm[i].id == selectid)
　        {
　　        if(elm[i].checked!=xState)
　　            elm[i].click();
　        }
　    }else
　    {
　        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
　        {
　　        if(elm[i].checked!=xState)
　　            elm[i].click();
　        }
　    }
}


//********************
//功能--翻转图片
//********************
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//------------------
function showHelp(id)
{ 
  var obj=document.getElementById(id);
  obj.style.display="";
  obj.style.left=event.clientX;
  obj.style.top=event.clientY;
}
function hidenHelp(id)
{
  var obj=document.getElementById(id);
  obj.style.display="none";
}
//图片自适应大小函数
var imageObject;
function ResizeImage(obj, MaxW, MaxH)
{
    if (obj != null) imageObject = obj;
    var state=imageObject.readyState;
    if(state==undefined)
        state=imageObject.complete;
    
	if(state!='complete' && state!=true) {
        setTimeout("ResizeImage(null,"+MaxW+","+MaxH+")",50);
		return;
    }
    var oldImage = new Image();
    oldImage.src = imageObject.src;
    var dW=oldImage.width; var dH=oldImage.height;
    if(dW>MaxW || dH>MaxH) {
        a=dW/MaxW; b=dH/MaxH;
        if(b>a) a=b;
        dW=dW/a; dH=dH/a;
    }
    if(dW > 0 && dH > 0) {
        imageObject.width=dW;
		imageObject.height=dH;
	}
}

function OriginImage(obj)
{
   var newImage=new Image();
   newImage.src=obj.src;
   var str="<img src='"+newImage.src+"'/>";
   var winname = window.open('IDPhoto', "_blank", '');
   winname.document.open('text/html', 'replace');
   winname.opener = null // 防止代码对论谈页面修改
   winname.document.write(str);
   winname.document.close();
}

//写Cookies
function setCookie(name,value,time){
    var strsec = getsec(time);
    var exp = new Date();
    exp.setTime(exp.getTime() + strsec*1);
    document.cookie += name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

function GoPage(value){
    AddParam("page",value)
}

function AddParam(name,value){
    
    var nowurl = location.href;

    if(nowurl.indexOf("?"+name+"=")==-1 && nowurl.indexOf("&"+name+"=")==-1)
    {
        if(nowurl.indexOf("?")==-1)
        {
            if(nowurl.indexOf("#")>=0)
            {   
                var nowurl1 = nowurl.split("#")[0];
                var nowurl2 = nowurl.split("#")[1];
                nowurl = nowurl1 + "?"+name+"="+value + "#" + nowurl2;
            }    
            else
                nowurl = nowurl+"?"+name+"="+value;
        }
        else
        {
            if(nowurl.indexOf("#")>=0)
            {
                var nowurl1 = nowurl.split("#")[0];
                var nowurl2 = nowurl.split("#")[1];
                nowurl = nowurl1 + "&"+name+"="+value + "#" + nowurl2;
            }else
                nowurl = nowurl+"&"+name+"="+value;
        }
    }
    else
    {
        var array;
        var m_index = nowurl.indexOf("?"+name+"=");
        if(m_index>=0){
            array = nowurl.split("?"+name+"=");
            nowurl = nowurl.substring(0,m_index)+"?"+name+"="+value;
        }
        else{
            m_index = nowurl.indexOf("&"+name+"=");
            array = nowurl.split("&"+name+"=");
            nowurl = nowurl.substring(0,m_index)+"&"+name+"="+value;
        }
        var tempString = array[1];
        if(tempString.indexOf("&")!=-1)
        {
           nowurl+=tempString.substring(tempString.indexOf("&"),tempString.length);
        }
        if(tempString.indexOf("#")!=-1)
        {
           nowurl+=tempString.substring(tempString.indexOf("#"),tempString.length);
        }
    }
        self.location.href = nowurl
}
